#encoding: utf-8

from urllib.parse import urlparse,urljoin
from flask import request

def is_safe_url(target):
    ref_url = urlparse(request.host_url)
    # 127.0.0.1:5050/?return_to=test
    test_url = urlparse(urljoin(request.host_url, target))
    #127.0.0.1:5050/?www.baidu.com
    return test_url.scheme in ('http', 'https') and \
           ref_url.netloc == test_url.netloc